home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / submods / fontreq / FontReq.b < prev    next >
Encoding:
Text File  |  1996-08-28  |  3.0 KB  |  135 lines

  1. {*
  2. ** ASL Font Requester for use in conjunction with ACE programs.
  3. **
  4. ** Author: David J Benn
  5. **   Date: 22nd January, 
  6. **       10th,13th February 1995,
  7. **       5th March 1995,
  8. **       29th September 1996
  9. *}
  10.  
  11. {*
  12. ** General constants.
  13. *}
  14. CONST true = -1&, false = 0&
  15. CONST null = 0&
  16.  
  17. {*
  18. ** ASL contants/values.
  19. *}
  20. CONST ASL_FontRequest    = 1
  21.  
  22. CONST FONF_FRONTCOLOR     = 1
  23. CONST FONF_BACKCOLOR    = 2
  24. CONST FONF_STYLES    = 4
  25. CONST FONF_FIXEDWIDTH    = 16
  26.  
  27. CONST TAG_DONE         = 0&
  28.  
  29. {*
  30. ** Structure definitions.
  31. *}
  32. STRUCT TagItem
  33.   LONGINT ti_Tag
  34.   LONGINT ti_Data
  35. END STRUCT
  36.  
  37. STRUCT TextAttr
  38.   ADDRESS  ta_Name
  39.   SHORTINT ta_YSize
  40.   BYTE       ta_Style
  41.   BYTE        ta_Flags
  42. END STRUCT
  43.  
  44. STRUCT FontRequester
  45.   ADDRESS  fo_Reserved1
  46.   ADDRESS  fo_Reserved2
  47.   TextAttr fo_Attr
  48.   BYTE       fo_FrontPen
  49.   BYTE       fo_BackPen
  50.   BYTE       fo_DrawMode
  51.   ADDRESS  fo_UserData
  52.   SHORTINT fo_LeftEdge
  53.   SHORTINT fo_TopEdge
  54.   SHORTINT fo_Width
  55.   SHORTINT fo_Height
  56. END STRUCT
  57.  
  58. STRUCT FontInfo
  59.   ADDRESS  fontName
  60.   SHORTINT fontHeight
  61.   SHORTINT textStyle
  62.   SHORTINT frontColor
  63.   SHORTINT backColor
  64. END STRUCT
  65.  
  66. {*
  67. ** Shared library function declarations.
  68. *}
  69. DECLARE FUNCTION ADDRESS AllocAslRequest(LONGINT type, ADDRESS ptags) LIBRARY asl
  70. DECLARE FUNCTION FreeAslRequest(ADDRESS request) LIBRARY asl
  71. DECLARE FUNCTION SHORTINT AslRequest(ADDRESS request, ADDRESS ptags) LIBRARY asl
  72.  
  73. DECLARE FUNCTION ADDRESS AllocateTagItems(LONGINT tags) LIBRARY utility
  74. DECLARE FUNCTION FreeTagItems(ADDRESS ptags) LIBRARY utility
  75.  
  76. {*
  77. ** Subprogram definitions.
  78. *}
  79. SUB LONGINT FontInfoRequest(ADDRESS theInfo) EXTERNAL
  80. DECLARE STRUCT TagItem *fontReqTags, *tag
  81. DECLARE STRUCT FontRequester *request
  82. DECLARE STRUCT TextAttr *theAttr
  83. DECLARE STRUCT FontInfo *info
  84. LONGINT ASL_FuncFlags, retVal
  85.  
  86.   LIBRARY "utility.library"
  87.   LIBRARY "asl.library"
  88.  
  89.   info = theInfo
  90.  
  91.   {* Allocate requester structure. *}
  92.   fontReqTags = AllocateTagItems(2)
  93.   IF fontReqTags = null THEN
  94.     retVal = false
  95.   ELSE
  96.     ASL_FuncFlags = SHL(1,31) + &H80000 + 20  {* see C header libraries/asl.h *}
  97.     tag = fontReqTags
  98.     tag->ti_Tag = ASL_FuncFlags
  99.     tag->ti_Data = FONF_FRONTCOLOR OR FONF_BACKCOLOR OR FONF_STYLES OR FONF_FIXEDWIDTH
  100.     tag = tag + SIZEOF(TagItem)
  101.     tag->ti_Tag = TAG_DONE
  102.  
  103.     request = AllocAslRequest(ASL_FontRequest, fontReqTags)
  104.  
  105.     IF request = null THEN 
  106.       retVal = false
  107.     ELSE
  108.       {* Render the requester. *}
  109.       IF AslRequest(request, null) THEN
  110.         {* Okay -> get font information. *}
  111.         theAttr = @request->fo_Attr
  112.         info->fontName = theAttr->ta_Name
  113.         info->fontHeight = theAttr->ta_YSize
  114.         info->textStyle = theAttr->ta_Style
  115.         info->frontColor = request->fo_FrontPen
  116.         info->backColor = request->fo_BackPen
  117.         retVal = true
  118.       ELSE
  119.         {* Requester cancelled. *}
  120.         retVal = false
  121.       END IF
  122.     END IF
  123.  
  124.     {* Clean up. *}
  125.     FreeAslRequest(request)
  126.     FreeTagItems(fontReqTags)
  127.  
  128.     LIBRARY CLOSE "asl.library"
  129.     LIBRARY CLOSE "utility.library"
  130.   END IF
  131.  
  132.   {* successful? *}
  133.   FontInfoRequest = retVal
  134. END SUB
  135.